/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: HelloController
 * Author:   kadibeieun
 * Date:     2019/9/2 15:45
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.afd.controlloer;

import com.afd.pojo.User;
import com.afd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;


/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author kadibeieun
 * @create 2019/9/2
 * @since 1.0.0
 */
@Controller
public class HelloController {
//    @Autowired
//    private DataSource dataSource;

    @Autowired
    private UserService userService;

//    @RequestMapping("/")
//    public String sayHello(){
//        return  "hello spring boot" + dataSource;
//    }

    @GetMapping("/hello.do")
    public User getUser(){
        User user = userService.queryById(20L);
        return user;
    }


    @GetMapping("all.do")
    public String all(ModelMap model){
        List<User> users = userService.queryAll();
        // 放入模型
        model.addAttribute("users", users);
        // 返回模板名称（就是classpath:/templates/目录下的html文件名）
        return "users";
    }

    @GetMapping("/hell.do")
    public String hello(Map<String,Object> map){
        map.put("name", "zhangsan");
        map.put("age", 18);
        return "hello";
    }

}